//
//  OneTableViewCell.m
//  LOLVideoPlayer
//
//  Created by SXW on 16/4/1.
//  Copyright © 2016年 盛宣伟. All rights reserved.
//

#import "OneTableViewCell.h"
#import "SDCycleScrollView.h"
static CGFloat CELL_HEIGHT = 150;

@interface OneTableViewCell () <SDCycleScrollViewDelegate>

@property(nonatomic,strong)SDCycleScrollView *scrollView;
@property(nonatomic,strong)NSMutableArray *arryImg;

@end


@implementation OneTableViewCell

// 第一步 初始化 试图
// 第二部 传入数据
// 第三部  加载 SDCycleScrollView

- (void)prepareForReuse
{
    [super prepareForReuse];
    [self.arryImg removeAllObjects];
    [_scrollView removeFromSuperview];
    _scrollView = nil;
    
}


- (void)setDataArray:(NSArray *)dataArray
{
    _dataArray = dataArray;
    CGRect frame = CGRectMake(0, 0, APPScreenWidth, CELL_HEIGHT  +50);
    UIImage *placeholderImage = [UIImage imageNamed:@""];
    _scrollView = [SDCycleScrollView cycleScrollViewWithFrame:frame delegate:self placeholderImage:placeholderImage];
    //需要整合数据
    for (OneModel *banner in _dataArray) {
        [self.arryImg addObject:[banner.photo stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    }
    //    UIImageView *imageView = [[UIImageView alloc]init];
    //    [imageView sd_setImageWithURL:nil];
    
    _scrollView.imageURLStringsGroup = self.arryImg;
    
    [self.contentView addSubview:_scrollView];
}
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    //第三种
    //        UIViewController *views = [[UIViewController alloc]init];
    //        views.view.backgroundColor=[UIColor redColor];
    //
    //    //寻找或传递给 下一个响应者
    //    UIResponder *responder = self.nextResponder;
    //
    //    while (![responder isKindOfClass:[UIViewController class]]) {
    //        responder = responder.nextResponder;
    //    }
    //    UIViewController *controller = (UIViewController *)responder;
    //    [controller.navigationController pushViewController:views animated:YES];
    
    
    //第二种
    [self.delegate pushController:_dataArray[index]];
    
    
    //第一种
    //    [self.controller.navigationController pushViewController:views animated:YES];
    
    
}

+(CGFloat)getCellHeight
{
    return CELL_HEIGHT;
}
- (NSMutableArray *)arryImg
{
    if (!_arryImg) {
        _arryImg = [NSMutableArray array];
    }
    return _arryImg;
}

@end
